<template>
    <div class="login_container">
        <!-- 大盒子 -->
        <div class="login_box">
            <!-- 头像框 -->
            <div class="avator_box">
                <img src="../assets/css/bgp8.png">
            </div>
            <el-form ref="loginFormRef" label-width="0px" :rules="loginFormRules" :model="loginForm">
                <!-- input框 -->
                <el-form-item prop="username" class="login_form1">
                    <el-input v-model="loginForm.username"  placeholder="Username" class="uinput"></el-input>
                </el-form-item>
                <el-form-item prop="password" class="login_form2" placeholder="Password">
                    <el-input v-model="loginForm.password" type="password" placeholder="Password" class="uinput"></el-input>
                </el-form-item>
                <!-- 提交按钮 -->
                <el-form-item>
                    <el-button type="primary" round @click="login" class="btn1">Login</el-button>
                    <el-button type="info" round @click="resetLoginForm" class="btn2">Reset</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loginFormRules: {
        username: [
          { required: true, message: 'Username is required', trigger: 'blur' },
          { min: 3, max: 10, message: 'Username must be in 3 to 10 words', trigger: 'blur' }
        ],
        password: [
          { required: true, message: 'Password is required', trigger: 'blur' },
          { min: 6, max: 15, message: 'Password must be in 6 to 15 words', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 重置
    resetLoginForm () {
      this.$refs.loginFormRef.resetFields()
    },
    login () {
      this.$refs.loginFormRef.validate(async (valid) => {
        // eslint-disable-next-line no-useless-return
        if (!valid) return
        const { data: res } = await this.$http.post('login', this.loginForm)
        if (res.meta.status !== 200) return this.$message.error('登录失败！')
        this.$message.success('登录成功！')
        window.sessionStorage.setItem('token', res.data.token)
        this.$router.push('/home')
      })
    }
  }
}
</script>

<style lang="less" scoped>
.login_container{
    overflow: hidden;
    height: 100%;
    position: relative;
    background-image: url('../assets/css/bgp3.jpg');
      // background: transparent url('../assets/css/bgp3.jpg') repeat-y  fixed center top ;
}

.login_box{
    width: 550px;
    height: 350px;
    background-color:rgba(3, 1, 26, 0.4);
    border-radius: 30px;
    position: relative;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -45%);
}

.avator_box{
    width: 110px;
    height: 110px;
    border: 1px solid transparent;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 0 10px rgba(3, 1, 26, 0.4);
    position: relative;
    left: 50%;
    transform: translate(-50%, -44%);
    background-color: rgba(61, 186, 243, 0.2);
    img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: beige;
    }
}

.login_form1{
  position: relative;
  left: 50%;
  top: 25%;
  transform: translate(-57%, -45%);
  width: 350px;
  box-sizing: border-box;
}

.login_form2 {
  position: relative;
  width:350px;
  box-sizing: border-box;
  left: 50%;
  bottom:25%;
  transform: translate(-57%, -80%);
}

.el-button--primary,
.el-button--info{
    position: absolute;
    height: 50px;
    width: 145px;
    margin: 0 45px;
    border-radius: 50px;
    border: none;
    outline: none;
    font-size: 20px;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    font-family: "Poppins";
}

.el-button.is-round{
  border-radius: 50px;
}

.btn1{
  bottom: 35px;
  left: 50px;
}

.btn1:hover{
    background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
    background-size: 400%;
}

.btn2{
  bottom: 35px;
  left: 300px;
}

.btn2:hover{
    background: linear-gradient(90deg, #fa7199, #f5ce62, #e43603, #fa7199);
    background-size: 400%;
}

.btn1::before,
.btn2::before{
    content: '';
    position: absolute;
    background: inherit;
    top: -5px;
    right: -5px;
    bottom: -5px;
    left: -5px;
    border-radius: 50px;
    filter: blur(20px);
    opacity: 0;
    transition: opacity 0.5s;
}

.btn1:hover::before,
.btn2:hover::before{
    opacity: 1;
    z-index: -1;
}

.btn1:hover,
.btn2:hover{
    z-index: 1;
    animation: glow 6s linear infinite;
}

@keyframes glow{
    0%{
        background-position: 0%;
    }
    100%{
        background-position: 400%;
    }
}

.uinput /deep/ .el-input__inner {
    border:0;
    background: none;
    display: block;
    margin: 20px auto;
    text-align: center;
    border: 2px solid rgba(52, 152, 219, 0.8);
    padding: 14px 10px;
    width: 400px;
    height: 50px;
    outline: none;
    border-radius: 24px;
    transition: 0.25s;
    font-size: 16px;
    }

.uinput /deep/ .el-input__inner:focus{
    width: 420px;
    border-color: rgb(94, 190, 253);
}

.el-form-item /deep/ .el-form-item__content /deep/ .el-form-item__error{
    top: 70px;
    left: 23px;
    width: 100%;
}
</style>
